package com.neusoft.elm_servlet.dao.impl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import java.util.List;

import com.neusoft.elm_servlet.dao.FoodDao;
import com.neusoft.elm_servlet.po.Food;
import com.neusoft.elm_servlet.util.DBUtil;

public class FoodDaoImpl implements FoodDao {

	@Override
	public List<Food> listFoodByBusinessId(String businessId) throws SQLException {
		Connection con = DBUtil.getConnection();
		PreparedStatement ps = con.prepareStatement("select * from food where businessId=?");
		ps.setString(1, businessId);
		ResultSet rs = ps.executeQuery();
		List<Food> list = new ArrayList<>();
		while(rs.next()){
			Food food = new Food();
			food.setFoodId(rs.getInt("foodId"));
			food.setFoodImg(rs.getString("foodImg"));
			food.setFoodName(rs.getString("foodName"));
			food.setFoodPrice(rs.getDouble("foodPrice"));
			food.setFoodExplain(rs.getString("foodExplain"));
			food.setRemarks(rs.getString("remarks"));
			list.add(food);
		}
		DBUtil.close(rs, ps, con);
		return list;
	}

}
